<template>

  <el-form :model="tableData" :rules="rules" ref="tableData" label-width="100px" class="demo-tableData">
    <el-card class="box-card">
      <span>基本信息</span>
      <div class="text item">
        <el-form-item label="订单号">
          <el-input v-model="tableData.orderNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请时间">
          <el-input v-model="tableData.addTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-input v-model="tableData.statusString" disabled></el-input>
        </el-form-item>
        <el-form-item label="汽车总数量">
          <el-input v-model="tableData.carSumNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="融资经销商">
          <el-input v-model="tableData.dealerName" disabled></el-input>
        </el-form-item>
        <el-form-item label="采购总金额(元)">
          <el-input type="textarea" :value="tableData.purchaseSumMoney | toFixed2" disabled></el-input>
          <span class="convertCurrency">{{tableData.purchaseSumMoney|convertCurrency}}</span>
        </el-form-item>
        <el-form-item label="融资总金额(元)">
          <el-input type="textarea" :value="tableData.mortgageSumMoney| toFixed2" disabled></el-input>
          <span class="convertCurrency">{{tableData.mortgageSumMoney|convertCurrency}}</span>
        </el-form-item>
        <el-form-item label="融资比例(%)">
          <el-input :value="(((tableData.mortgageSumMoney)/(tableData.purchaseSumMoney)*100-0).toFixed(2)||'')+'%'" disabled></el-input>
        </el-form-item>

        <el-form-item label="初始融资周期"  prop="durationId">
          <el-select v-model="tableData.durationId" placeholder="请选择借款时长" :disabled="dialogSendData.isAdd">
             <el-option label="请选择" value=""></el-option>
            <el-option v-for="(item,index) in tableData.carOrderDurationList" :label="item.description" :value="item.id" :key="index">
            </el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="初始融资利率" prop="mortgageInterestRate">
          <el-input v-number='4' v-model.number="tableData.mortgageInterestRate" placeholder='只可输入数字、小数点，四位小数限制20位'  :maxlength='20' :disabled="dialogSendData.isAdd"></el-input>
        </el-form-item>

        <el-form-item label="业务员" prop="businessSysUsersId">
          <el-select v-model="tableData.businessSysUsersId" placeholder="请选择业务员" :disabled="dialogSendData.isAdd">
             <el-option label="请选择" value=""></el-option>            
            <el-option v-for="(item,index) in yewuyuan" :label="item.realname" :value="item.id" :key="index">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="收款账号">
          <qiniu v-if='tableData.receivableAccountPic' :qiniuImage="tableData.receivableAccountPics" :id="tableData.receivableAccountPics.id" :canDelete="false"></qiniu>
        </el-form-item>
        <el-form-item label="收款账户名" prop="accountName">
          <el-input v-model="tableData.accountName" placeholder="限制30字" :disabled="dialogSendData.isAdd"></el-input>
        </el-form-item>
        <el-form-item label="收款账号" prop="accountNumber">
          <el-input v-model="tableData.accountNumber" placeholder="限制30字" :disabled="dialogSendData.isAdd"></el-input>
        </el-form-item>
        <el-form-item label="开户行" prop="openningBank">
          <el-input v-model="tableData.openningBank" placeholder="限制30字" :disabled="dialogSendData.isAdd"></el-input>
        </el-form-item>

        <el-form-item label="资金方" prop='funderId'>
          <el-select v-model.number="tableData.funderId" placeholder="请选择资金方" :disabled="dialogSendData.isAdd" v-on:change="getSpvUser()">
             <el-option label="请选择" value=""></el-option>            
            <el-option v-for="(item,index) in selectFunder" :label="item.realname" :value="item.id" :key="index">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="SPV">
          <el-input :value="selectSpvUser.spvId" auto-complete="off" disabled></el-input>
        </el-form-item>

        <el-form-item label="资源审核意见">
          <el-input v-model="tableData.resourceAuditOpinion" disabled></el-input>
        </el-form-item>
        <el-form-item label="资源审核人">
          <el-input v-model="tableData.resourceAuditPeople" disabled></el-input>
        </el-form-item>
        <el-form-item label="资源审核时间">
          <el-input :value="getDate(tableData.resourceAuditTime)" disabled></el-input>
        </el-form-item>


        <el-form-item label="物管验车意见">
          <el-input v-model="tableData.propertyInspectionOpinion" disabled></el-input>
        </el-form-item>
        <el-form-item label="物管验车审核人">
          <el-input v-model="tableData.propertyInspectionPeople" disabled></el-input>
        </el-form-item>
        <el-form-item label="物管验车审核时间">
          <el-input :value="getDate(tableData.propertyInspectionTime)" disabled></el-input>
        </el-form-item>


      </div>
    </el-card>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>车辆信息</span>
      </div>
      <el-collapse v-model="activeNames" @change="handleChange" v-for='(items,index) in tableData.carTypes ' :key='items'>
        <el-collapse-item :title="items.carName" name="1">
          <div class="text item">
            <el-form-item label="指导价 ">
              <el-input :value="items.guidePrice| toFixed2" disabled></el-input>
               <span class="convertCurrency">{{items.guidePrice|convertCurrency}}</span>
            </el-form-item>
            <el-form-item label="配置 ">
              <el-input v-model="items.carConfig" type='textarea' disabled></el-input>
            </el-form-item>
            <el-form-item label="采购单价(元) ">
              <el-input :value="items.carPurchasePrice| toFixed2" disabled></el-input>
              <span class="convertCurrency">{{items.carPurchasePrice|convertCurrency}}</span>
            </el-form-item>
            <el-form-item label="汽车数量 ">
              <el-input v-model="items.carCount" disabled></el-input>
            </el-form-item>
            <el-form-item label="采购金额(元) ">
              <el-input :value="items.carPurchaseMoney| toFixed2" disabled></el-input>
              <span class="convertCurrency">{{items.carPurchaseMoney|convertCurrency}}</span>
            </el-form-item>
            <el-form-item label="融资金额(元)" prop="money">
              <el-input :value="items.carMortgageMoney| toFixed2" disabled></el-input>
              <span class="convertCurrency">{{items.carMortgageMoney|convertCurrency}}</span>
            </el-form-item>
            <el-form-item label="采购合同">
              <qiniu v-if='items.carContractPics?true:false' :qiniuImage="items.carContractPics" :id="items.carContractPics.id" :canDelete="false"></qiniu>
            </el-form-item>

          <el-container v-for='(item,key) in items.mortgageInspectionList' :key='key'>
            <el-header class='title'>数量{{index+1}}</el-header>
            <el-form-item label="汽车颜色">
              <el-input v-model="item.color" disabled></el-input>
            </el-form-item>
            <el-form-item label="车架号">
              <el-input v-model="item.vin" disabled></el-input>
            </el-form-item>
            <el-form-item label="发动机号">
              <el-input v-model="item.engineNumber" disabled></el-input>
            </el-form-item>
            <el-form-item label="生产日期">
              <el-input v-model="item.productionDate" disabled></el-input>
            </el-form-item>

            <el-form-item v-if='item.inspectionPics?true:false' label="验车照片">
              <qiniu :qiniuImage="item.inspectionPics" :id="item.inspectionPics.id" :canDelete="false"></qiniu>
            </el-form-item>
            <el-form-item v-if='item.inspectionPics?true:false' label="手续照片">
              <qiniu :qiniuImage="item.proceduresPics" :id="item.proceduresPics.id" :canDelete="false"></qiniu>
            </el-form-item>
          </el-container>

          </div>
        </el-collapse-item>


      </el-collapse>
    </el-card>
    <el-form-item label="二审是否通过" prop="status" style='marginTop:20px' >
      <el-radio v-model="tableData.status" :label="10040" :disabled="dialogSendData.isAdd">通过</el-radio>
      <el-radio v-model="tableData.status" :label="10050" :disabled="dialogSendData.isAdd">不通过</el-radio>
    </el-form-item>
    <el-card class="box-card">
      <el-form-item label="风控审核意见" prop="riskAuditOpinion">
        <el-input v-model="tableData.riskAuditOpinion" placeholder="必填，100字限制。" :maxlength='100' :disabled="dialogSendData.isAdd"></el-input>
      </el-form-item>
    </el-card>
    <el-form-item class='align'>
      <el-button type="primary" @click="resetForm('tableData')">返回</el-button>
      <el-button type="success" @click="submitForm('tableData')" v-if="!dialogSendData.isAdd">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import qiniu from '@/views/qiniu/upload';
  import agentHttp from '@/utils/agentHttp.js';
  import {qiniuArray,timestampToTime} from '@/utils/index.js';
  
  import {
    require,
    prop,
    decimalTwo,
    max100,
    chk
  } from '@/utils/rules.js' //表单验证规则

  export default {
    data() {
      return {
        tableData: {
            opinion:'',
            rate:'',
            status:'',
        },
        rules: {
          funderId:[require("资金方不能为空")],
          durationId: [require("初始融资周期")],
			    mortgageInterestRate:[require('初始融资利率'),{ validator: chk, trigger: "blur"}],
          businessSysUsersId: [require("业务员")],
          accountName: [require("收款账户名")],
          accountNumber: [require("收款账号")],
          openningBank: [require("开户行")],
          riskAuditOpinion: [require("风控审核意见")],
          status:[require("二审是否通过")]
        },
        radio: '',
        yewuyuan: {},
        //资金方
        selectFunder: [],
        //spv
        selectSpvUser: {},
      };
    },
    methods: {
      submitForm(formName) {      //提交数据
        this.$refs[formName].validate(valid => {
          if (valid) {
              var params = {
                  mortgageOrderExtendId:this.tableData.id,
                  durationId:this.tableData.durationId,
                  mortgageInterestRate:this.tableData.mortgageInterestRate,
                  businessSysUsersId:this.tableData.businessSysUsersId,
                  receivableAccountPic:this.tableData.receivableAccountPic,
                  accountName:this.tableData.accountName,
                  accountNumber:this.tableData.accountNumber,
                  openningBank:this.tableData.openningBank,
                  funderId:this.tableData.funderId,
                  spvId:this.tableData.spvId,
                  status:this.tableData.status,
                  riskAuditOpinion:this.tableData.riskAuditOpinion  
              }
              agentHttp.postJson(`adminApi/admin/mortgage_order_risk/second_order/sumbit`,params).then(res=>{
                this.$message.success(res.data||" 提交成功");  
                this.$emit("Refresh", null);                
                this.dialogSendData.dialogFormVisible = false;
              })
              

          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.dialogSendData.dialogFormVisible = false;
      },

      initData() { //初始化数据
        agentHttp.get(`adminApi/admin/mortgage_order_risk/second_order_detail/${this.mortgageOrderExtendId}`).then((
          data) => {

          this.tableData = Object.assign({}, data.data.orderInfo, this.tableData);
          this.yewuyuan = data.data.yewuyuan;
          //资金方
          this.selectFunder = data.data.funderUser;
         
          if (this.tableData.businessSysUsersId==null) {
            this.tableData.businessSysUsersId= this.tableData.dealerBusinessSysUsersId;

          }
            qiniuArray( this.tableData)
          //加青牛节点
                       
          if(this.tableData.receivableAccountPic!==null){
            
              this.tableData.receivableAccountPics = {
                id: 'this.tableData.receivableAccountPic',
                image_uri: this.tableData.receivableAccountPic.split(',').notempty()
              }
          }  
        })
      },

      //spv
      getSpvUser() {
        for (var i = 0; i < this.selectFunder.length; i++) {
          if (this.selectFunder[i].id == this.tableData.funderId) {
            if (null != this.selectFunder[i].spv) {
              this.selectSpvUser = this.selectFunder[i].spv;
              this.tableData.spvId = parseInt(this.selectFunder[i].spv.id);
              return;
            } else {
              this.tableData.spvId = null;
              this.selectSpvUser = {};
            }
          } else {
            this.tableData.spvId = null;
            this.selectSpvUser = {};
          }
        }
       
      },
      inspect(code,data){
        var type = decimalTwo ;
          return muchVerification(code,data,type)
      },
      getDate(time){
        return timestampToTime(time)
      }

    },
    props: {
      dialogSendData: {
        type: Object
      },
      mortgageOrderExtendId: {
        type: Number
      }
    },
    mounted() {
      this.initData();
    },
    components: {
      qiniu
    }
  };

</script>

<style lang="scss" scoped>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both;
  }

  .box-card {
    margin-top: 20px;
  }

  .align {
    margin: 50px auto 0;
    text-align: center;
  }

</style>

